package com.songVersion.services.impl;

import java.util.HashMap;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;

import com.songVersion.model.Cover;
import com.songVersion.model.ThumbnailCache;
import com.songVersion.services.CoverManager;

public class CoverManagerImpl extends CountingManagerImpl<Cover> implements
		CoverManager
{

	Cover theCover;
	
	private boolean loadParodies;
	
	@Override
	protected void addHit(Cover t)
	{
		t.setHits(t.getHits() + 1);
		
	}

	@Override
	protected void initResultList(List<Cover> l)
	{
		for (Cover c: l)
		{
			@SuppressWarnings("unused")
			ThumbnailCache t = c.getThumb();

		}
	}
	@SuppressWarnings("unchecked")
	@Override
	protected Cover doLoadBean(PersistenceManager pm)
	{
		Query query = pm.newQuery(Cover.class);
		query.setFilter("songName == nameParam");
		query.declareParameters("String nameParam");
		List<Cover> l = (List<Cover>) query.execute(theCover.getSongName());
		
		if (l == null || l.size() == 0)
			return null;
		else
			return l.get(0);
		
	}

	@Override
	protected Cover newBean()
	{
		Cover c = new Cover(theCover.getSongName(), theCover.getThumb());
		return c;
	}

	@Override
	public void init()
	{
		this.t = new Cover("", null);
		
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	@Override
	protected void setParams()
	{
		isFiltered = true;
		filter = "isParody == parodyParam";
		declaredParameters = "Boolean parodyParam";
		parameters = new HashMap();
		parameters.put("parodyParam", loadParodies);
	}

	public Cover getTheCover()
	{
		return theCover;
	}

	public void setTheCover(Cover theCover)
	{
		this.theCover = theCover;
	}

	public boolean isLoadParodies() {
		return loadParodies;
	}

	public void setLoadParodies(boolean loadParodies) {
		this.loadParodies = loadParodies;
	}

	
}
